#ifndef ARRAY_H_
#define ARRAY_H_
#include "conf.h"

C_CODE_BEGIN 
struct array {
	size_t rsize;
	size_t usize;
	size_t objsize;
	void* buffer;
};

EXPORT_FUNC struct array* array_create( struct array* , size_t rsize , size_t objsize );
EXPORT_FUNC void array_destroy( struct array* );

EXPORT_FUNC void array_push_back( struct array* , void* obj );
EXPORT_FUNC void array_pop_back( struct array* );

EXPORT_FUNC void array_expand( struct array* , size_t size);
EXPORT_FUNC void* array_index_at( struct array*, int idx );
EXPORT_FUNC struct array* array_clone( struct array* src, struct array* des );
/*
 * personally , I prefer foreach closure (if c has :) than iterator 
 */
EXPORT_FUNC void array_foreach( struct array* , void (*func)(void*obj,int idx,void* others) , void* others );
EXPORT_FUNC void array_until( struct array* , bool (*func)(void* obj,int idx,void* others), void* others);

EXPORT_FUNC void array_trim( struct array* );
EXPORT_FUNC void array_reserve( struct array* , size_t size );
EXPORT_FUNC void array_clear( struct array* );

#define array_get_capacity(array) ((array)->rsize)
#define array_get_usesize(array) ((array)->usize)
#define array_get_objsize(array) ((array)->objsize)

C_CODE_END

#endif // ARRAY_H_